<?php
/**
 * Products index controller
 * 
 * @author Konstantin Shamko <konstantin.shamko@gmail.com> 
 * @version 0.0.1
 * @copyright  Copyright (c) 2009 Konstantin Shamko
 * @package Products Module
 * @license  New BSD License
 *
 */
class products_ProductsController extends Bel_Controller{
	
	/**
	 * Displays products list with paging. Each page has 9 items
	 *
	 */
	public function indexAction(){
		$this->_seo->setTitle($this->_seo->getTitle().' products');
		$oProducts = new Models_Products();
		$oProducts->setItemsOnPage(9);
		$products = $oProducts->getProductsByCategory($this->_request->getParam('cat_id'),null,$this->_request->getParam('page'));
		$this->view->assign('products',$products);
		$this->view->assign('paging',$oProducts->getPaging($_SERVER['REDIRECT_URL'].'?page='));
		$this->view->display('products/products/bycategory.tpl');
	}
	
	/**
	 * Displays product details
	 *
	 */
	public function detailsAction(){
		
		$product_id = $this->_request->getParam('product_id');
		
		if (! ($product = $this->_cache->load ( 'product'.$product_id ))) {
			$oProducts = new Models_Products();
			$product = $oProducts->getFullProductInfo($product_id); 
			$this->_cache->save ( $product );
		}
			
		if($product){
			$this->_seo->setTitle($product['product']['product_name']);
			$this->_seo->setDescription($product['product']['product_meta_description']);
			$this->_seo->setKeywords($product['product']['product_meta_keywords']);
			$this->view->assign('product',$product);
			$this->view->display('products/products/details.tpl');
		}else{
			$this->_response->setHeader ( 'HTTP/1.x', '404 Not found' );
			$this->_response->clearBody ();
			$this->view->display ( '404.tpl' );
			$this->_response->sendHeaders ();
			die ();			
		}
	}
}